xtset cowcode year

global country "country"
global year "year"
global iv "iv_all spatial"
global control1 "l.ln_gdp_pcap l.gdp_growth l.trade l.kaopen l.nat_res l.inflation l.unemp_labor"
global control2 "l.ln_gdp_pcap l.gdp_growth l.trade l.kaopen l.nat_res l.inflation l.unemp_labor l.polity5 l.exec_id l.urban l.efindex l.civil_war"
global control3 "l.ln_gdp_pcap l.gdp_growth l.trade l.kaopen l.nat_res l.polity5 l.exec_id"


***Table 1***
xtivreg2 gini_mkt $control1 (ter_all_pcap = $iv) yrdum*, fe first gmm robust
xtivreg2 gini_mkt $control2 (ter_all_pcap = $iv) yrdum*, fe first gmm robust
xtivreg2 gini_disp $control1 (ter_all_pcap = $iv) yrdum*, fe first gmm robust
xtivreg2 gini_disp $control2 (ter_all_pcap = $iv) yrdum*, fe first gmm robust


**************************Appendix**************************

***Table A3: Mediation Analysis***
sem (icrg_qog<- ter_all_pcap $control3) (gini_disp <-icrg_qog ter_all_pcap $control2),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (inc_assist<- ter_all_pcap $control3) (gini_disp <-inc_assist ter_all_pcap $control2),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (soc_assist<- ter_all_pcap $control3) (gini_disp <-soc_assist ter_all_pcap $control2),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (military_expend<- ter_all_pcap $control3) (gini_disp <- military_expend ter_all_pcap $control2),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (gdp_pcap_growth<- ter_all_pcap $control3) (gini_disp <- gdp_pcap_growth ter_all_pcap $control2),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (gf_gdp<- ter_all_pcap $control3) (gini_disp <- gf_gdp ter_all_pcap $control2),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)


***Table A4: Casualties***
xtivreg2 gini_mkt $control1 (kill_tot_pcap = $iv), fe first gmm robust
xtivreg2 gini_mkt $control2 (kill_tot_pcap = $iv), fe first gmm robust
xtivreg2 gini_disp $control1 (kill_tot_pcap = $iv), fe first gmm robust
xtivreg2 gini_disp $control2 (kill_tot_pcap = $iv), fe first gmm robust


***Table A5: Developing***
xtivreg2 gini_mkt $control2 (ter_all_pcap = $iv) yrdum* if developed==0, fe first gmm robust
xtivreg2 gini_disp $control2 (ter_all_pcap = $iv) yrdum* if developed==0, fe first gmm robust


***Table A6: Domestic vs. International***
global ivd "iv_dom spatial"
global ivi "iv_int spatial"

xtivreg2 gini_mkt $control2 (ter_dom_pcap = $ivd) yrdum*, fe first gmm robust
xtivreg2 gini_mkt $control2 (ter_int_pcap = $ivi) yrdum*, fe first gmm robust
xtivreg2 gini_disp $control2 (ter_dom_pcap = $ivd) yrdum*, fe first gmm robust
xtivreg2 gini_disp $control2 (ter_int_pcap = $ivi) yrdum*, fe first gmm robust


***Table A7: Regions Excluded***
xtivreg2 gini_disp $control2 (ter_all_pcap = $iv) yrdum* if region!=4, fe first gmm 
xtivreg2 gini_disp $control2 (ter_all_pcap = $iv) yrdum* if region!=1, fe first gmm 
xtivreg2 gini_disp $control2 (ter_all_pcap = $iv) yrdum* if region!=5 & region!=6, fe first gmm 
xtivreg2 gini_disp $control2 (ter_all_pcap = $iv) yrdum* if region!=4 & region!=5 & region!=6, fe first gmm 


***Table A8: Mediation with Instrument Variables***
sem (icrg_qog<- pred_ter_all_pcap $control3 res)(gini_disp <-icrg_qog pred_ter_all_pcap $control2 res),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (inc_assist<- pred_ter_all_pcap $control3 res)(gini_disp <-inc_assist pred_ter_all_pcap $control2 res),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (soc_assist<- pred_ter_all_pcap $control3 res)(gini_disp <-soc_assist pred_ter_all_pcap $control2 res),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (military_expend<- pred_ter_all_pcap $control3 res)(gini_disp <-military_expend pred_ter_all_pcap $control2 res),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (gdp_pcap_growth<- pred_ter_all_pcap $control3 res)(gini_disp <-gdp_pcap_growth pred_ter_all_pcap $control2 res),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)
sem (gf_gdp<- pred_ter_all_pcap $control3 res)(gini_disp <-gf_gdp pred_ter_all_pcap $control2 res),  covstruct(_lexogenous,diagonal) cov(_lexogenous*_oexogenous@0) nocapslatent vce(r)